function Food(ele){

this.ele=ele
this.len=20
this.foodX = 0
this.foodY = 0
this.foodObj=null

}

//出现食物
Food.prototype.create=function(){

    let divObj=document.createElement('div')

    divObj.style.width=this.len+'px'
    divObj.style.height=this.len+'px'
    divObj.style.position='absolute'
    divObj.style.background='black'

    this.ele.appendChild(divObj)


    this.foodObj=divObj
    this.move()

}

//
Food.prototype.move=function(){

    let foodXmax=this.ele.clientWidth/this.len-1
    let foodYmax=this.ele.clientHeight/this.len-1

    //Math.floor(Math.random() * (max-min+1)+min) 
    this.foodX = Math.floor(Math.random() * (foodXmax-0+1)+0)*this.len
    this.foodY = Math.floor(Math.random() * (foodYmax-0+1)+0)*this.len


    this.foodObj.style.left=this.foodX+'px'
    this.foodObj.style.top=this.foodY+'px'

}




